package com.yuexunit.operationman.nbsy.module.Placement.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.Placement.bean.PlacementBean;
import com.yuexunit.operationman.nbsy.module.Placement.model.impl.PlacementDetailModel;
import com.yuexunit.operationman.nbsy.module.Placement.presenter.IPlacementDetailPresenter;
import com.yuexunit.operationman.nbsy.module.Placement.presenter.impl.PlacementDetailPresenter;
import com.yuexunit.operationman.nbsy.module.Placement.ui.view.IPlacementDetailView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/3/6 0006.
 */

public class Act_Placement_Main extends BaseKJActivity implements IPlacementDetailView{
    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.usr_head)
    ImageView usrHead;
    @Bind(R.id.usr_name)
    TextView usrName;
    @Bind(R.id.usr_age)
    TextView usrAge;
    @Bind(R.id.usr_gender)
    TextView usrGender;
    @Bind(R.id.ops_date)
    TextView opsDate;
    @Bind(R.id.doc_name)
    TextView docName;
    @Bind(R.id.preops_diagnosis)
    TextView preopsDiagnosis;
    @Bind(R.id.position)
    TextView position;
    @Bind(R.id.recipe_date)
    TextView recipeDate;
    @Bind(R.id.recipe_id)
    TextView recipeId;
    @Bind(R.id.hisPatientNo)
    TextView hisPatientNo;

    IPlacementDetailPresenter presenter;

    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_placement_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new PlacementDetailPresenter(this,new PlacementDetailModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        params.put("deviceType","1");
        presenter.getPlacementDate(params);
    }

    private void setTitle()
    {
        titlebarTvTitle.setText("内置固定放置术登记表");
    }

    @OnClick({R.id.titlebar_img_back, R.id.placement_content, R.id.placement_sign, R.id.preview})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.placement_content:
                startActivity(new Intent(aty, Act_Placement_Content.class));
                break;
            case R.id.placement_sign:
                startActivity(new Intent(aty, Act_Placement_Sign.class));
                break;
            case R.id.preview:
                startActivity(new Intent(aty, Act_Placement_Preview.class));
                break;
        }
    }

    @Override
    public void getPlacementDate(PlacementBean placementBean) {
        if(placementBean.getCode() == 200)
        {
            AppConfig.PLACEMENTBEAN =placementBean;
            usrName.setText(AppConfig.PLACEMENTBEAN.getObject().getPatientName());
            usrAge.setText(AppConfig.PLACEMENTBEAN.getObject().getAge());
            if(AppConfig.PLACEMENTBEAN.getObject().getSex().equals("1")) {
                usrGender.setText("男");
            }else if(AppConfig.PLACEMENTBEAN.getObject().getSex().equals("2"))
            {
                usrGender.setText("女");
            }
            else {
                usrGender.setText("不详");
            }
            opsDate.setText(AppConfig.PLACEMENTBEAN.getObject().getOperationDate());
            docName.setText(AppConfig.PLACEMENTBEAN.getObject().getOperator());
            preopsDiagnosis.setText(AppConfig.PLACEMENTBEAN.getObject().getPreOperation());
            position.setText(AppConfig.PLACEMENTBEAN.getObject().getDepName());
            recipeDate.setText(AppConfig.PLACEMENTBEAN.getObject().getOperationName());
            recipeId.setText(AppConfig.PLACEMENTBEAN.getObject().getBedNo());
            hisPatientNo.setText(AppConfig.PLACEMENTBEAN.getObject().getHospitalNo());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
